home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Flex 2.5.2 / flex-2.5.2 / MacUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  1.5 KB  |  87 lines  |  [TEXT/MPS ]

  1. /***
  2.  *
  3.  * MacUtils.c - by Christopher E. Hyde, 95-06-29
  4.  *
  5.  ***/
  6.  
  7. #include    <stdio.h>
  8. #include    <stdlib.h>
  9. #include    <fcntl.h>
  10. #include    <ioctl.h>
  11.  
  12. #include    <Memory.h>
  13. #include    <Resources.h>
  14.  
  15.  
  16. int
  17. isatty (int fd)
  18. {
  19.     return ioctl(fd, FIOINTERACTIVE, NULL) == 0;
  20. }
  21.  
  22.  
  23. typedef Boolean bool;
  24. typedef struct {
  25.     Handle    data;
  26.     Size    size;
  27. } CSkel;
  28.  
  29. static CSkel aSkel = { nil, 0 };
  30.  
  31.  
  32. bool
  33. HGets (CSkel* this, char* buf)
  34. {
  35.     char* s;
  36.     if (skel_ind >= this->size) {
  37.         HPurge(this->data);
  38.         return false;
  39.     }
  40.  
  41. //    if (!*this->data)
  42.         LoadResource(this->data);
  43.     s = &(*this->data)[skel_ind];
  44.     do {
  45.         ++skel_ind;
  46.     } while ((*buf++ = *s++) != '\n');
  47.     *buf = '\0';
  48.  
  49.     return true;
  50. }
  51.  
  52.  
  53. /* skelout - write out one section of the skeleton file
  54.  *
  55.  * Description
  56.  *    Copies skelfile or skel array to stdout until a line beginning with
  57.  *    "%%" or EOF is found.
  58.  */
  59. void
  60. skelout (void)
  61. {
  62.     char    buf[MAXLINE];
  63.     bool    do_copy = true;
  64.  
  65.         // Loop pulling lines either from the skelfile,
  66.         // if we're using one, or from the skel[] array.
  67.  
  68.     if (!skelfile && skel_ind == 0) {
  69.         aSkel.data = Get1Resource('TEXT', 128);
  70.         aSkel.size = GetHandleSize(aSkel.data);
  71.     }
  72.  
  73.     while (skelfile ? (fgets(buf, MAXLINE, skelfile) != NULL)
  74.                     : HGets(&aSkel, buf)) {    /* copy from skel array */
  75.         if (buf[0] == '%') {    /* control line */
  76.             switch ( buf[1] ) {
  77.                 case '%':    return;
  78.                 case '+':    do_copy = C_plus_plus;            break;
  79.                 case '-':    do_copy = !C_plus_plus;            break;
  80.                 case '*':    do_copy = true;                    break;
  81.                 default:    flexfatal( _( "bad line in skeleton file" ) );
  82.             }
  83.         } else if (do_copy)
  84.             out(buf);
  85.     }
  86. }
  87.